<?php


namespace app\admin\model;


use app\common\model\BaseModel;

class Role extends BaseModel
{
    // 当前角色的所有权限
    public function rules(){
        return $this->belongsToMany('Rule','role_rule');
    }

    /**
     * 获取角色
     * @return array
     *
     */
    public function getRoleList(){
        $param = request()->param();
        $limit = intval(getValByKey('limit',$param,10));
        $page = intval(getValByKey('page',$param,1));
        $totalCount = $this->count();
        $list = $this->with(['rules'=>function($q){
            $q->alias('a')->field('a.id');
        }])->page($page,$limit)->order([
            'id'=>'desc'
        ])->select();
        return [
            'list'=>$list,
            'totalCount'=>$totalCount
        ];
    }

    public function managers()
    {
        return $this->hasMany('Manager');
    }
}